package com.example.config;

import lombok.Setter;
import lombok.ToString;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author yexi
 */
@Setter
@ToString(callSuper = true)
@Component
@Scope("prototype")
public class PrototypeClass {

    private String msg;

    public PrototypeClass() {
        //在配置文件配置好之后。当Spring容器启动时，就会为对应的类创建bean，因此该方法会被调用输出。
        System.out.println("PrototypeClass的bean对象被创建了" + this);
    }

    @PostConstruct
    public void init() {
        System.out.println("PrototypeClass初始化");
        this.msg = "成功初始化";
    }

    @PreDestroy
    public void close() {
        System.out.println("PrototypeClass销毁");
    }
}
